﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Text;
using System.Web.SessionState;

namespace jnagr.Web.zuowu
{
    /// <summary>
    /// GetZW 的摘要说明
    /// </summary>
    public class GetZW : IHttpHandler, IRequiresSessionState
    {
        jnagr.BLL.zuowuinfo bll = new jnagr.BLL.zuowuinfo();
        jnagr.BLL.growinfo bllg = new jnagr.BLL.growinfo();
        jnagr.BLL.ruleinfo bllr = new jnagr.BLL.ruleinfo();
        jnagr.BLL.devinfo blld = new jnagr.BLL.devinfo();
        public void ProcessRequest(HttpContext context)
        {

            string ac = "";
            if (null != context.Request.Form["action"])
            {//获取前台传来的值  
                ac = context.Request.Form["action"].ToString().Trim();
            }
            else if (null != context.Request.QueryString["action"])
            {
                ac = context.Request.QueryString["action"].ToString().Trim();
            }

            if (ac == "query")
                Query(context);
            else if (ac == "queryq")
                Queryq(context);
            else if (ac == "modifyq")
                modifyq(context);
            else if (ac == "queryyx")
                Queryyx(context);
            else if (ac == "modifyyx")
                modifyyx(context);
            else if (ac == "queryr")
                Queryr(context);
            else if (ac == "addr")
                addr(context);
            else if (ac == "modifyr")
                modifyr(context);
            else if (ac == "deleter")
                deleter(context);
            else if (ac == "querysz")
                Querysz(context);
            else if (ac == "addsz")
                addsz(context);
            else if (ac == "modifysz")
                modifysz(context);
            else if (ac == "deletesz")
                deletesz(context);
            else if (ac == "add")
                add(context);

            else if (ac == "modify")
                modify(context);

            else if (ac == "delete")
                delete(context);

            else if (ac == "ddllist")
                ddllist(context);
            else if (ac == "ddllistsz")
                ddllistsz(context);
            else if (ac == "queryrs")
                Queryrs(context);
            else if (ac == "queryszs")
                Queryszs(context);
        }
        public void Queryszs(HttpContext context)
        {


            context.Response.ContentType = "text/plain";
            int uid = Web.Admin.myinfo.getID(context);
            if (uid != 0)
            {
                int grid = 0;
                if (null != context.Request.QueryString["grid"])
                {
                    grid = int.Parse(context.Request.QueryString["grid"].ToString().Trim());
                }
                
                if (grid != 0)
                {
                    string sql = string.Format("grid={0} ", grid);
                    DataSet ds = bllg.GetList(1, sql, "grid desc");
                    string json = "";
                    if (ds != null && ds.Tables[0].Rows.Count > 0)
                        json = "[{\"gx\":\"" + ds.Tables[0].Rows[0]["gx"].ToString() + "\",\"gpic\":\"" + ds.Tables[0].Rows[0]["gpic"].ToString() + "\"}]";
                    context.Response.Write(json);
                }
                context.Response.End();
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();

            }
        }
        public void Queryrs(HttpContext context)
        {


            context.Response.ContentType = "text/plain";
            int uid = Web.Admin.myinfo.getID(context);
            if (uid != 0)
            {                
                int gid = 0, sz = 0;
                if (null != context.Request.QueryString["gid"])
                {
                    gid = int.Parse(context.Request.QueryString["gid"].ToString().Trim());
                }               
                if (null != context.Request.QueryString["sz"])
                {
                    sz = int.Parse(context.Request.QueryString["sz"].ToString().Trim());
                }
                if (gid != 0 && sz != 0)
                {
                    string sql = string.Format("gid={0} and grid={1} ", gid, sz);
                    DataSet ds = bllr.GetList(1, sql, "rid desc");
                    string json="";
                    if(ds!=null&&ds.Tables[0].Rows.Count>0)
                        json = "[{\"lvalue\":\"" + ds.Tables[0].Rows[0]["lvalue"].ToString() + "\",\"hvalue\":\"" + ds.Tables[0].Rows[0]["hvalue"].ToString() + "\",\"gx\":\"" + ds.Tables[0].Rows[0]["gx"].ToString() + "\"}]";
                    context.Response.Write(json);
                }
                context.Response.End();
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();

            }
        }
        public void Queryyx(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int uid = Web.Admin.myinfo.getID(context);
            if (uid != 0)
            {
                string dtype = "YBQ", sebm = "";

                //================================================================  
                //获取分页和排序信息：页大小，页码，排序方式，排序字段  
                int pageRows, page;
                pageRows = 10;
                page = 1;
                string order, sort, oderby; order = sort = oderby = "";

                if (null != context.Request.Form["sebm"])
                {
                    sebm = context.Request.Form["sebm"].ToString().Trim();
                }
                StringBuilder strWhere = new StringBuilder();
                if (dtype != "")
                {
                    strWhere.AppendFormat(" DevType='{0}' and ", dtype);
                }
                string[] pcc = Web.Admin.myinfo.getPCC(context).Split(',');
                string add = string.Join("", pcc);
                strWhere.AppendFormat(" DevLocation like '{0}%' and ", add);
                int startindex = strWhere.ToString().LastIndexOf("and");//获取最后一个and的位置  
                if (startindex >= 0)
                {
                    strWhere.Remove(startindex, 3);//删除多余的and关键字  
                }
                if (sort != "" && order != "")
                {
                    oderby = order + " " + sort;
                }
                DataSet ds = blld.GetListByPage(strWhere.ToString(), oderby, (page - 1) * pageRows + 1, page * pageRows);
                int count = blld.GetRecordCount(strWhere.ToString());//获取条数  
                string strJson = ToJson.Dataset2Json(ds, count);//DataSet数据转化为Json数据  
                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();

            }
        }
        public void modifyyx(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int uid = Web.Admin.myinfo.getID(context);
            if (uid != 0)
            {
                int KeyId = 0;
                string uidstr = context.Request.Form["KeyIdc"];
                if (uidstr != "")
                    KeyId = int.Parse(uidstr);
                string chn0 = context.Request.Form["changedatetime"];
                DateTime dt = DateTime.Parse(chn0);

                jnagr.Model.devinfo model = new jnagr.Model.devinfo();
                model.KeyId = KeyId;
                model.changedatetime = dt;               
                if (blld.Updateyx(model))
                {
                    context.Response.Write("T");//返回给前台页面  
                    context.Response.End();
                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();
                }
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }
        }
        public void Queryq(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int uid = Web.Admin.myinfo.getID(context);
            if (uid != 0)
            {
                string dtype = "TSQ", sebm = "";

                //================================================================  
                //获取分页和排序信息：页大小，页码，排序方式，排序字段  
                int pageRows, page;
                pageRows = 10;
                page = 1;
                string order, sort, oderby; order = sort = oderby = "";

                if (null != context.Request.Form["sebm"])
                {
                    sebm = context.Request.Form["sebm"].ToString().Trim();
                }
                StringBuilder strWhere = new StringBuilder();
                if (dtype != "")
                {
                    strWhere.AppendFormat(" DevType='{0}' and ", dtype);
                }
                string[] pcc = Web.Admin.myinfo.getPCC(context).Split(',');
                string add = string.Join("", pcc);
                strWhere.AppendFormat(" DevLocation like '{0}%' and ", add);
                int startindex = strWhere.ToString().LastIndexOf("and");//获取最后一个and的位置  
                if (startindex >= 0)
                {
                    strWhere.Remove(startindex, 3);//删除多余的and关键字  
                }
                if (sort != "" && order != "")
                {
                    oderby = order + " " + sort;
                }
                DataSet ds = blld.GetListByPage(strWhere.ToString(), oderby, (page - 1) * pageRows + 1, page * pageRows);
                int count = blld.GetRecordCount(strWhere.ToString());//获取条数  
                string strJson = ToJson.Dataset2Json(ds, count);//DataSet数据转化为Json数据  
                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();

            }
        }
        public void modifyq(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int uid = Web.Admin.myinfo.getID(context);
            if (uid != 0)
            {
                int KeyId = 0;
                string uidstr = context.Request.Form["KeyId"];
                if (uidstr != "")
                    KeyId = int.Parse(uidstr);

                string chn0 = context.Request.Form["chn0"];
                string chn1 = context.Request.Form["chn1"];
                string chn2 = context.Request.Form["chn2"];
                string chn02 = context.Request.Form["chn02"];
                string chn12 = context.Request.Form["chn12"];
                string chn22 = context.Request.Form["chn22"];
                string chn03 = context.Request.Form["chn03"];
                string chn13 = context.Request.Form["chn13"];
                string chn23 = context.Request.Form["chn23"];
                string chn04 = context.Request.Form["chn04"];
                string chn14 = context.Request.Form["chn14"];
                string chn24 = context.Request.Form["chn24"];
                string chn05 = context.Request.Form["chn05"];
                string chn15 = context.Request.Form["chn15"];
                string chn25 = context.Request.Form["chn25"];
                string hgid1 = context.Request.Form["hgid1"];
                string hgid2 = context.Request.Form["hgid2"];
                string hgid3 = context.Request.Form["hgid3"];
                string hgid4 = context.Request.Form["hgid4"];
                string hgid5 = context.Request.Form["hgid5"];
                jnagr.Model.devinfo model = new jnagr.Model.devinfo();
                model.KeyId = KeyId;
                model.chn0 = chn0 + "," + chn02 + "," + chn03 + "," + chn04 + "," + chn05;
                model.chn1 = chn1 + "," + chn12 + "," + chn13 + "," + chn14 + "," + chn15;
                model.chn2 = chn2 + "," + chn22 + "," + chn23 + "," + chn24 + "," + chn25;
                model.XQHID = hgid1 + "," + hgid2 + "," + hgid3 + "," + hgid4 + "," + hgid5;

                if (blld.Updatecs(model))
                {
                    context.Response.Write("T");//返回给前台页面  
                    context.Response.End();
                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();
                }
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }
        }
        public void addr(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int uid = Web.Admin.myinfo.getID(context);
            if (uid != 0)
            {
                int level = Web.Admin.myinfo.getLevel(context);
                if (level == 1)
                {
                    string g = context.Request.Form["gid"];
                    string zw = context.Request.Form["sz"];
                    //string gx = context.Request.Form["gx"];
                    int zwid = 0, gid = 0;
                    int.TryParse(zw, out zwid);
                    int.TryParse(g, out gid);
                    string l = context.Request.Form["lvalue"];
                    string h = context.Request.Form["hvalue"];
                    decimal lv = 0, hv = 0;
                    decimal.TryParse(l, out lv);
                    decimal.TryParse(h, out hv);
                    jnagr.Model.ruleinfo model = new jnagr.Model.ruleinfo();
                    model.gid = gid;
                    model.grid = zwid;
                    model.lvalue = lv;
                    model.hvalue = hv;
                    //model.gx = gx;
                    if (bllr.Add(model) > 0)
                    {
                        context.Response.Write("T");//返回给前台页面  
                        context.Response.End();
                    }
                    else
                    {
                        context.Response.Write("F");//返回给前台页面  
                        context.Response.End();
                    }
                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();
                }
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }

        }
        public void modifyr(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int uid = Web.Admin.myinfo.getID(context);
            if (uid != 0)
            {
                int level = Web.Admin.myinfo.getLevel(context);
                if (level == 1)
                {
                    int mid = 0;
                    string uidstr = context.Request.Form["rid"];
                    if (uidstr != "")
                        mid = int.Parse(uidstr);
                    string g = context.Request.Form["gid"];
                    string zw = context.Request.Form["sz"];
                    //string gx = context.Request.Form["gx"];
                    int zwid = 0, gid = 0;
                    int.TryParse(zw, out zwid);
                    int.TryParse(g, out gid);
                    string l = context.Request.Form["lvalue"];
                    string h = context.Request.Form["hvalue"];
                    decimal lv = 0, hv = 0;
                    decimal.TryParse(l, out lv);
                    decimal.TryParse(h, out hv);
                    jnagr.Model.ruleinfo model = new jnagr.Model.ruleinfo();
                    model.gid = gid;
                    model.grid = zwid;
                    model.lvalue = lv;
                    model.hvalue = hv;
                    //model.gx = gx;
                    model.rid = mid;
                    if (bllr.Update(model))
                    {
                        context.Response.Write("T");//返回给前台页面  
                        context.Response.End();
                    }
                    else
                    {
                        context.Response.Write("F");//返回给前台页面  
                        context.Response.End();
                    }
                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();
                }
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }
        }

        public void deleter(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int uid = 0;
            string uidstr = context.Request.QueryString["rid"];
            if (uidstr != "")
                uid = int.Parse(uidstr);
            int level = Web.Admin.myinfo.getLevel(context);
            if (level == 1)
            {
                if (bllr.Delete(uid))
                {
                    context.Response.Write("T");//返回给前台页面  
                    context.Response.End();
                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();
                }
            }
            else
            {
                context.Response.Write("F");//返回给前台页面  
                context.Response.End();
            }
        }
        public void Queryr(HttpContext context)
        {


            context.Response.ContentType = "text/plain";
            int uid = Web.Admin.myinfo.getID(context);
            if (uid != 0)
            {
                string uname, utruename;
                uname = utruename = "";
                //获取前台传来的值 

                //================================================================  
                //获取分页和排序信息：页大小，页码，排序方式，排序字段  
                int pageRows, page;
                pageRows = 10;
                page = 1;
                string order, sort, oderby; order = sort = oderby = "";
                if (null != context.Request.Form["rows"])
                {
                    pageRows = int.Parse(context.Request.Form["rows"].ToString().Trim());
                }
                if (null != context.Request.Form["page"])
                {
                    page = int.Parse(context.Request.Form["page"].ToString().Trim());
                }
                if (null != context.Request.Form["sort"])
                {
                    order = context.Request.Form["sort"].ToString().Trim();
                }
                if (null != context.Request.Form["order"])
                {
                    sort = context.Request.Form["order"].ToString().Trim();
                }

                if (sort != "" && order != "")
                {
                    oderby = order + " " + sort;
                }
                string areas = Web.Admin.myinfo.getPCC(context).Replace(",", "");
                DataSet ds = bllr.GetListByPage(" zwarea ='" + areas + "'", oderby, (page - 1) * pageRows + 1, page * pageRows);
                int count = bllr.GetRecordCount(" zwarea ='" + areas + "'");//获取条数  
                string strJson = ToJson.Dataset2Json(ds, count);//DataSet数据转化为Json数据  
                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();

            }
        }
        public void addsz(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int uid = Web.Admin.myinfo.getID(context);
            if (uid != 0)
            {
                int level = Web.Admin.myinfo.getLevel(context);
                if (level == 1)
                {
                    string mname = context.Request.Form["gname"];
                    string zw = context.Request.Form["zwids"];
                    string gx = context.Request.Form["gx"];
                    int zwid = 0;
                    int.TryParse(zw, out zwid);
                    string savepath = "";
                    HttpFileCollection files = context.Request.Files;
                    if (files.Count == 1)
                    {
                        HttpPostedFile file = files[0];
                        if (file.ContentLength > 0)
                        {
                            //全路径  
                            string FullFullName = file.FileName;
                            //获取图片的名称  
                            String fileName = FullFullName.Substring(FullFullName.LastIndexOf("\\") + 1);
                            string exp = fileName.Substring(fileName.LastIndexOf('.')).ToLower();
                            string filenames = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                            string path = "~/szpics";
                            savepath = "/szpics";
                            if (exp == ".jpg" || exp == ".bmp" || exp == ".gif" || exp == ".png")
                            {
                                file.SaveAs(System.Web.HttpContext.Current.Server.MapPath(path) + "\\" + filenames + exp);
                                savepath += "/" + filenames + exp;
                            }
                            else
                            {
                                context.Response.Write("P");//返回给前台页面  
                                context.Response.End();

                            }
                        }
                    }
                    jnagr.Model.growinfo model = new jnagr.Model.growinfo();
                    model.gname = mname;
                    model.zwid = zwid;
                    model.gpic = savepath;
                    model.gx = gx;

                    if (bllg.Add(model) > 0)
                    {
                        context.Response.Write("T");//返回给前台页面  
                        context.Response.End();
                    }
                    else
                    {
                        context.Response.Write("F");//返回给前台页面  
                        context.Response.End();
                    }
                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();
                }
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }

        }
        public void modifysz(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int uid = Web.Admin.myinfo.getID(context);
            if (uid != 0)
            {
                int level = Web.Admin.myinfo.getLevel(context);
                if (level == 1)
                {
                    int mid = 0;
                    string uidstr = context.Request.Form["grid"];
                    if (uidstr != "")
                        mid = int.Parse(uidstr);
                    string mname = context.Request.Form["gname"];
                    string zw = context.Request.Form["zwids"];
                    string gx = context.Request.Form["gx"];
                    int zwid = 0;
                    int.TryParse(zw, out zwid);
                    string hmpic = context.Request.Form["mpic"];
                    string savepath = "";
                    HttpFileCollection files = context.Request.Files;
                    if (files.Count == 1)
                    {
                        HttpPostedFile file = files[0];
                        if (file.ContentLength > 0)
                        {
                            //全路径  
                            string FullFullName = file.FileName;
                            //获取图片的名称  
                            String fileName = FullFullName.Substring(FullFullName.LastIndexOf("\\") + 1);
                            string exp = fileName.Substring(fileName.LastIndexOf('.')).ToLower();
                            string filenames = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                            string path = "~/szpics";
                            savepath = "/szpics";
                            if (exp == ".jpg" || exp == ".bmp" || exp == ".gif" || exp == ".png")
                            {
                                file.SaveAs(System.Web.HttpContext.Current.Server.MapPath(path) + "\\" + filenames + exp);
                                savepath += "/" + filenames + exp;
                            }
                            else
                            {
                                context.Response.Write("P");//返回给前台页面  
                                context.Response.End();

                            }
                        }
                        else
                        {
                            savepath = hmpic;

                        }
                    }
                    else
                    {
                        savepath = hmpic;

                    }
                    jnagr.Model.growinfo model = new jnagr.Model.growinfo();
                    model.gname = mname;
                    model.zwid = zwid;
                    model.grid = mid;
                    model.gpic = savepath;
                    model.gx = gx;
                    if (bllg.Update(model))
                    {
                        context.Response.Write("T");//返回给前台页面  
                        context.Response.End();
                    }
                    else
                    {
                        context.Response.Write("F");//返回给前台页面  
                        context.Response.End();
                    }
                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();
                }
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }
        }

        public void ddllistsz(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int uid = Web.Admin.myinfo.getID(context);
            if (uid != 0)
            {
                int zwid = 0;
                if (null != context.Request.QueryString["zwid"])
                {
                    string zw = context.Request.QueryString["zwid"].ToString().Trim();

                    int.TryParse(zw, out zwid);
                }
                StringBuilder strWhere = new StringBuilder();
                string areas = Web.Admin.myinfo.getPCC(context).Replace(",", "");
                DataSet ds = bllg.GetList(" zwid =" + zwid);
                string strJson = ToJson.DataTable2Json1(ds.Tables[0]);//DataSet数据转化为Json数据  
                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();

            }
        }
        public void deletesz(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int uid = 0;
            string uidstr = context.Request.QueryString["grid"];
            if (uidstr != "")
                uid = int.Parse(uidstr);
            int level = Web.Admin.myinfo.getLevel(context);
            if (level == 1)
            {
                if (bllg.Delete(uid))
                {
                    context.Response.Write("T");//返回给前台页面  
                    context.Response.End();
                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();
                }
            }
            else
            {
                context.Response.Write("F");//返回给前台页面  
                context.Response.End();
            }
        }
        public void Querysz(HttpContext context)
        {


            context.Response.ContentType = "text/plain";
            int uid = Web.Admin.myinfo.getID(context);
            if (uid != 0)
            {
                string uname, utruename;
                uname = utruename = "";
                //获取前台传来的值 

                //================================================================  
                //获取分页和排序信息：页大小，页码，排序方式，排序字段  
                int pageRows, page;
                pageRows = 10;
                page = 1;
                string order, sort, oderby; order = sort = oderby = "";
                if (null != context.Request.Form["rows"])
                {
                    pageRows = int.Parse(context.Request.Form["rows"].ToString().Trim());
                }
                if (null != context.Request.Form["page"])
                {
                    page = int.Parse(context.Request.Form["page"].ToString().Trim());
                }
                if (null != context.Request.Form["sort"])
                {
                    order = context.Request.Form["sort"].ToString().Trim();
                }
                if (null != context.Request.Form["order"])
                {
                    sort = context.Request.Form["order"].ToString().Trim();
                }

                if (sort != "" && order != "")
                {
                    oderby = order + " " + sort;
                }
                string areas = Web.Admin.myinfo.getPCC(context).Replace(",", "");
                DataSet ds = bllg.GetListByPage(" zwarea ='" + areas + "'", oderby, (page - 1) * pageRows + 1, page * pageRows);
                int count = bllg.GetRecordCount(" zwarea ='" + areas + "'");//获取条数  
                string strJson = ToJson.Dataset2Json(ds, count);//DataSet数据转化为Json数据  
                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();

            }
        }
        public void ddllist(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int uid = Web.Admin.myinfo.getID(context);
            if (uid != 0)
            {
                StringBuilder strWhere = new StringBuilder();
                string areas = Web.Admin.myinfo.getPCC(context).Replace(",", "");
                DataSet ds = bll.GetList(" zwarea like '" + areas + "%'");
                string strJson = ToJson.DataTable2Json1(ds.Tables[0]);//DataSet数据转化为Json数据  
                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();

            }
        }
        public void delete(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int uid = 0;
            string uidstr = context.Request.QueryString["zwid"];
            if (uidstr != "")
                uid = int.Parse(uidstr);
            int level = Web.Admin.myinfo.getLevel(context);
            if (level == 1)
            {
                if (bll.Delete(uid))
                {
                    context.Response.Write("T");//返回给前台页面  
                    context.Response.End();
                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();
                }
            }
            else
            {
                context.Response.Write("F");//返回给前台页面  
                context.Response.End();
            }
        }
        public void modify(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int uid = Web.Admin.myinfo.getID(context);
            if (uid != 0)
            {
                int level = Web.Admin.myinfo.getLevel(context);
                if (level == 1)
                {
                    int mid = 0;
                    string uidstr = context.Request.Form["zwid"];
                    if (uidstr != "")
                        mid = int.Parse(uidstr);
                    string mname = context.Request.Form["zwname"];

                    jnagr.Model.zuowuinfo model = new jnagr.Model.zuowuinfo();

                    model.zwname = mname;
                    model.zwid = mid;
                    if (bll.Update(model))
                    {
                        context.Response.Write("T");//返回给前台页面  
                        context.Response.End();
                    }
                    else
                    {
                        context.Response.Write("F");//返回给前台页面  
                        context.Response.End();
                    }
                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();
                }
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }
        }
        public void add(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int uid = Web.Admin.myinfo.getID(context);
            if (uid != 0)
            {
                string[] area = Web.Admin.myinfo.getPCC(context).Split(',');
                BLL.areainfo ba = new BLL.areainfo();
                int level = Web.Admin.myinfo.getLevel(context);
                if (level == 1)
                {
                    string areas = string.Join("", area);
                    string abh = ba.GetAbh(1, area);
                    string mname = context.Request.Form["zwname"];
                    jnagr.Model.zuowuinfo model = new jnagr.Model.zuowuinfo();
                    model.zwname = mname;
                    model.areabm = abh;
                    model.zwarea = areas;
                    if (bll.Add(model) > 0)
                    {
                        context.Response.Write("T");//返回给前台页面  
                        context.Response.End();
                    }
                    else
                    {
                        context.Response.Write("F");//返回给前台页面  
                        context.Response.End();
                    }
                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();
                }
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }

        }
        public void Query(HttpContext context)
        {


            context.Response.ContentType = "text/plain";
            int uid = Web.Admin.myinfo.getID(context);
            if (uid != 0)
            {
                string uname, utruename;
                uname = utruename =  "";
                //获取前台传来的值 

                //================================================================  
                //获取分页和排序信息：页大小，页码，排序方式，排序字段  
                int pageRows, page;
                pageRows = 10;
                page = 1;
                string order, sort, oderby; order = sort = oderby = "";
                if (null != context.Request.Form["rows"])
                {
                    pageRows = int.Parse(context.Request.Form["rows"].ToString().Trim());
                }
                if (null != context.Request.Form["page"])
                {
                    page = int.Parse(context.Request.Form["page"].ToString().Trim());
                }
                if (null != context.Request.Form["sort"])
                {
                    order = context.Request.Form["sort"].ToString().Trim();
                }
                if (null != context.Request.Form["order"])
                {
                    sort = context.Request.Form["order"].ToString().Trim();
                }

                if (sort != "" && order != "")
                {
                    oderby = order + " " + sort;
                }
                string areas = Web.Admin.myinfo.getPCC(context).Replace(",", "");
                DataSet ds = bll.GetListByPage(" zwarea ='" + areas + "'", oderby, (page - 1) * pageRows + 1, page * pageRows);
                int count = bll.GetRecordCount(" zwarea ='" + areas + "'");//获取条数  
                string strJson = ToJson.Dataset2Json(ds, count);//DataSet数据转化为Json数据  
                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();

            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}